﻿@using Apps.Web.Core;
@using Apps.Models.Sys;
@using Apps.Web;
@using Apps.Common;
@using Apps.Locale;
@using Apps.Models.WC;
@{
    ViewBag.Title = "主页";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div class="mvctool">
    <input id="txtQuery" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create, ref perm, "Create", true)
    @Html.ToolButton("btnEdit", "fa fa-pencil", "修改备注信息", ref perm, "Edit", true)
    @Html.ToolButton("btnSync", "fa fa-pencil", "手动同步用户信息", ref perm, "Edit", true)
    @Html.ToolButton("btnMoveUser", "fa fa-pencil", "批量移动分组", ref perm, "Edit", true)
    @Html.ToolButton("btnDetails", "fa fa-list", Resource.Details, ref perm, "Details", true)
    @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete, ref perm, "Delete", false)
    <div class="rightdiv color-green">
        当前操作公众号：<span id="CurrentOfficalAccount">@(ViewBag.CurrentOfficalAcount)</span>
    </div>
</div>
<table id="List"></table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")
<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width:SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(37),
            fitColumns: true,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: false,//单选模式
            checkOnSelect: true,
            selectOnCheck: true,
            //rownumbers: true,//行号
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'Id', title: '系统ID', width: 80,hidden:true },
                { field: 'OpenId', title: 'OpenID', width: 80,sortable:true },
                { field: 'NickName', title: '昵称', width: 80,sortable:true },
                { field: 'Sex', title: '性别', width: 80,sortable:true },
                { field: 'Language', title: '区域语言', width: 80,sortable:true },
                { field: 'City', title: '城市', width: 80,sortable:true },
                { field: 'Province', title: '省份', width: 80,sortable:true },
                { field: 'Country', title: '国家', width: 80,sortable:true },
                { field: 'HeadImgUrl', title: '头像', width: 80,sortable:true },
                { field: 'SubscribeTime', title: '同步时间', width: 80,sortable:true },
                { field: 'UnionId', title: 'UnionId', width: 80,sortable:true },
                { field: 'Remark', title: '备注', width: 80,sortable:true },
                { field: 'GroupId', title: '分组', width: 80,sortable:true },
                { field: 'TagidList', title: '标签', width: 80,sortable:true },
                { field: 'Subscribe', title: '关注状态', width: 80,sortable:true },
                { field: 'OfficalAccountId', title: '所属公众号', width: 80,sortable:true }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s('@Resource.Tip', mes);
    }
    $(function () {
        $("#btnSync").click(function () {
            dataBatchOperater("@Url.Action("SyncUser")", "List");
        });
        $("#btnCreate").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0'' src='@Url.Action("Create")'></iframe>");
            $("#modalwindow").window({ title: '@Resource.Create', width: 700, height: 400, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("Edit")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 700, height: 400, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s('@Resource.Tip', '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='auto' frameborder='0' src='@Url.Action("Details")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Details', width: 700, height: 400, iconCls: 'fa fa-list' }).window('open');
            } else { $.messageBox5s('@Resource.Tip', '@Resource.PlaseChooseToOperatingRecords'); }
	        });
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: encodeURI(queryStr) });

        });
        $("#btnDelete").click(function () {
            dataBatchOperater("@Url.Action("Delete")", "List");
        });
        //批量移动分组
        $("#btnMoveUser").click(function () {
            var rows = $('#List').datagrid('getSelections');
            var ids = "";
            if (rows.length > 0) {
                $.each(rows, function (index, row) {
                    ids = ids + row.Id + ",";
                });
                ids = ids.substring(0, ids.length - 1);
                $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("MoveUser")?id=" + ids + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 300, height: 200, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s('@Resource.Tip', '@Resource.PlaseChooseToOperatingRecords'); }
        });
            
    });
</script>
